package part07_组合模式_学校院系展示;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: Universty
 * @Author: AllenSun
 * @Date: 2020/3/2 20:03
 */
//Universty其实就是Composite，可以管理College
public class Universty extends OrganizationComponent {

    List<OrganizationComponent> organizationComponents=new ArrayList<OrganizationComponent>();

    //构造器
    public Universty(String name, String des) {
        super(name, des);
    }

    /**重写add方法
     * @MethodName: add
     * @Author: AllenSun
     * @Date: 2020/3/2 21:14
     */
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        organizationComponents.add(organizationComponent);
    }

    /**重写remove方法
     * @MethodName: remove
     * @Author: AllenSun
     * @Date: 2020/3/2 21:14
     */
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    /**实现抽象方法，打印
     * @MethodName: print
     * @Author: AllenSun
     * @Date: 2020/3/2 21:14
     */
    @Override
    protected void print() {
        System.out.println("================"+getName()+"================");
        //遍历
        for (OrganizationComponent organizationComponent : organizationComponents) {
            organizationComponent.print();
        }
    }
}
